import java.util.Locale;

class Person {

}
public class Test {
    public static void main(String[] args) {
        String str1 = "abcd";
        String str2 = new String("abcd");
        System.out.println(str1 == str2);

        String str3 = "abcd";
        System.out.println(str1 == str3);
    }
    public static void main16(String[] args) {
        String str = "   hello   abcd   ";
        System.out.println(str);
        String ret = str.trim();
        System.out.println(ret);
    }
    public static void main15(String[] args) {
        String str = "abcdefgh";

        String s = str.substring(2);
        System.out.println(s);

        String s2 = str.substring(2,6);//[2,6)
        System.out.println(s2);
    }
    public static void main14(String[] args) {
        String str = "name=zhangsan&age=18" ;
        String[] strs = str.split("&");
        for (int i = 0; i < strs.length; i++) {
            //System.out.println(strs[i]);
            String[] strings = strs[i].split("=");
            for(String s : strings) {
                System.out.println(s);
            }
        }
    }
    public static void main13(String[] args) {
        String str1 = "192&168=1";
        String[] strs = str1.split("&|=");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }
    public static void main12(String[] args) {
        String str1 = "192\\168\\0\\1";
        String[] strs = str1.split("\\\\");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }
    public static void main11(String[] args) {
        String str1 = "192.168.0.1";
        String[] strs = str1.split("\\.");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }
    public static void main10(String[] args) {
        String str1 = "hello litter bitter";
        String[] strs = str1.split(" ");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
        System.out.println("===============");
        String[] str3 = str1.split(" ",2);
        for (int i = 0; i < str3.length; i++) {
            System.out.println(str3[i]);
        }
    }
    public static void main9(String[] args) {
        String str1 = "ababcabcdabcde";
        String ret1 = str1.replace('a','p');
        System.out.println(ret1);

        String ret2 = str1.replace("ab","ooo");
        System.out.println(ret2);

        String ret3 = str1.replaceAll("ab","666");
        System.out.println(ret3);

        String ret4 = str1.replaceFirst("ab","999");
        System.out.println(ret4);
    }
    public static void main8(String[] args) {
        String str1 = "abcdef";
        //字符串转数组
        char[] array = str1.toCharArray();
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
        //数组转字符串
        String  str2 = new String(array);
        System.out.println(str2);

        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);

    }
    public static void main7(String[] args) {
        String str1 = "abcd";
        String str2 = "ABcd";
        System.out.println(str1.toUpperCase());
        System.out.println(str2.toLowerCase());
    }
    public static void main6(String[] args) {
        //数字转字符
        String str2 = String.valueOf(123);
        System.out.println(str2);
        String str3 = String.valueOf(new Person());
        System.out.println(str3);
        System.out.println("==============");
        //字符转数字
        String str1 ="123";
        //基本类型对应的 类 类型，所以 基本类型 也提供了面向对象的思想
        int data = Integer.parseInt(str1);
        System.out.println(data);
        double data2 = Double.parseDouble(str1);
        System.out.println(data2);
    }
    public static void main5(String[] args) {
        String str1 = "ababcabcdabcde";

        char ch = str1.charAt(1);
        System.out.println(ch);
        for (int i = 0; i < str1.length(); i++) {
            System.out.print(str1.charAt(i)+" ");
        }
        System.out.println();
        System.out.println("================");
        System.out.println(str1.indexOf('c'));
        System.out.println(str1.indexOf('c',7));
        //在主串中 查找子串
        System.out.println(str1.indexOf("abcd"));
        System.out.println(str1.indexOf("abcd",6));
        System.out.println("=================");

        System.out.println(str1.lastIndexOf('a'));
        System.out.println(str1.lastIndexOf('a',8));
        System.out.println(str1.lastIndexOf("abc"));
        System.out.println(str1.lastIndexOf("abc",5));
    }
    public static void main4(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("Hello");
        //str1 和 str2 进行比较
        System.out.println(str1.compareTo(str2));
        //str1>str2返回正数，str1<str2返回负数，str1=str2返回0
        //忽略大小写进行比较
        System.out.println(str1.compareToIgnoreCase(str2));

        System.out.println(str1.equalsIgnoreCase(str2));


    }
    public static void main3(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);
        //比较两个引用 所指向的对象当中的内容是否一致
        System.out.println(str1.equals(str2));
    }
    public static void main2(String[] args) {
        String str1 = "hello";
        System.out.println(str1.length());
        int[] array = {1,2,3,4};
        System.out.println(array.length);

        String str2 = "";
        System.out.println(str2.length());// 获取字符串长度
        System.out.println(str2.isEmpty());// 如果字符串长度为0，返回true，否则返回false
        String str3 = null;
        System.out.println("dddd".length());
    }
    public static void main1(String[] args) {
        // 使用常量串构造
        String str1 = "hello";
        System.out.println(str1);

        // 直接newString对象
        String str2 = new String("hello");
        System.out.println(str2);

        // 使用字符数组进行构造
        //字符数组
        char[] values = {'a','b','c','d'};
        String str3 = new String(values);
        System.out.println(str3);
    }
}
